<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class WodedingdanController extends Controller
{
    //
    public function Index(Request $request)
    {   

        
        //从session查询用户id
        $user = session('user');
        
        $data = DB::table('dingdan')->where('uid',$user->userId)->get();

       foreach ($data as $key => $value) {
      
                //取得所有的订单中的pid
                $indent[$key] = $value->pid;
                //把所有pid转为数组
                foreach ($indent as $k => $v) {
                        
                        //如果字符串的长度大于1 则转为数组
                        if(strlen($v) > 1){

                            $indentpid[$k] = explode ( "," , $v );
                            foreach ($indentpid as $ke => $va) {
                                
                                foreach ($va as $kk => $vv) {

                                     $goodsmainpid[$ke][$kk] = DB::table('goodsmain')
                                    ->where('id',$vv)
                                    ->select('name','title','price','colour','pic0','id')
                                    ->first();
                                   
                                }
                               
                            }
                        }else{
                                 $goodsmainpid[$k] = DB::table('goodsmain')
                                    ->where('id',$v)
                                    ->select('name','title','price','colour','pic0','id')
                                    ->first();
                            
                        }
                        
                    
                }

 }
            
     // dd($goodsmainpid);
     // dd($data);
      

          return view('home.wodedingdan',['data'=>$data,'goodsmainpid'=> $goodsmainpid]);   
           
        }
       
          
      
}
    	
    
